package com.joyintech.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.joyintech.feign.FcFeignService;
import com.joyintech.util.ResponseData;
import com.joyintech.util.Verify;
import com.joyintech.util.ZhfxCode;
import com.joyintech.vo.RiskAssessVo;
import com.joyintech.vo.customQuery.CustomQueryReq;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Log4j2
@RestController
@RequestMapping("/intf")
public class IntfController {

    @Autowired
    private FcFeignService fcFeignService;


    /**
     * 查询资产配置详情
     *
     * @param message
     * @return
     */
    @PostMapping(value = "/customQuery", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String customQuery(@RequestBody String message) throws Exception {
        String decMessage = Verify.decMessage(message);
        CustomQueryReq customQueryReq = JSON.parseObject(decMessage,CustomQueryReq.class);
        log.info("请求报文 {}",JSON.toJSONString(customQueryReq));
        String result = fcFeignService.customQuery(customQueryReq);
        log.info("{}", JSON.toJSONString(result));
        JSONObject jsonObject = JSON.parseObject(result);
        String response = Verify.encMessage(jsonObject.toJSONString());
        return response;
    }

    /**
     * 查询资产配置详情
     *
     * @param message
     * @return
     */
    @PostMapping(value = "/riskAssess", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String riskAssess(@RequestBody String message) throws Exception {
        String decMessage = Verify.decMessage(message);
        RiskAssessVo vo = JSON.parseObject(decMessage,RiskAssessVo.class);
        String result = fcFeignService.riskAssess(vo);
        log.info("{}", JSON.toJSONString(result));
        JSONObject jsonObject = JSON.parseObject(result);
        String response = Verify.encMessage(jsonObject.toJSONString());
        return response;
    }

    @PostMapping(value = "/qualifiedInvestors", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String qualifiedInvestors(@RequestBody String message) throws Exception {
        String decMessage = Verify.decMessage(message);
        com.joyintech.vo.qualifiedInvestors.Request vo = JSON.parseObject(decMessage,com.joyintech.vo.qualifiedInvestors.Request.class);
        String result = fcFeignService.qualifiedInvestors(vo);
        log.info("{}", JSON.toJSONString(result));
        JSONObject jsonObject = JSON.parseObject(result);
        String response = Verify.encMessage(jsonObject.toJSONString());
        return response;
    }

}
